package com.nxn.core.web.tag;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.Validate;
import org.apache.log4j.Logger;

/**
 * Holds data for the "lrsux" infrastructure program uses.
 * 
 * @author Michael Zhang
 */
class FileRepository {
	private static final Logger LOGGER = Logger.getLogger(FileRepository.class);

	private static Map<String, Group> assets = new HashMap<String, Group>();
	private static boolean debug = true;

	/**
	 * Returns all assets data.
	 * 
	 * @return The Map, never be null.
	 */
	public static Map<String, Group> getAssets() {
		return assets;
	}

	/**
	 * Sets all assets data.
	 * 
	 * @param assets
	 *            The assets data, can not be null.
	 * 
	 * @throws IllegalArgumentException
	 *             Thrown when the "assets" is null.
	 */
	public static void setAssets(Map<String, Group> assets) throws IllegalArgumentException {
		Validate.notNull(assets, "The 'assets' is null");

		FileRepository.assets = assets;

		LOGGER.info("Set assets data to repository");
	}

	/**
	 * Returns whether the "lrsux" infrastructure is run in debug mode or not.
	 * 
	 * @return True, if run in debug mode. Otherwise returns false.
	 */
	public static boolean isDebug() {
		return debug;
	}

	/**
	 * Sets whether the "lrsux" infrastructure is run in debug mode or not.
	 * 
	 * @param debug
	 *            True, if run in debug mode. Otherwise sets to false.
	 */
	public static void setDebug(boolean debug) {
		FileRepository.debug = debug;

		LOGGER.info("Set the 'debug' mode to: " + FileRepository.debug);
	}
}
